package com.wenjie.redHat.controller;


import com.wenjie.redHat.commom.R;
import com.wenjie.redHat.domain.dto.RegisterDto;
import com.wenjie.redHat.domain.dto.UserDto;
import com.wenjie.redHat.domain.entity.UserEntity;
import com.wenjie.redHat.service.UserService;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class userController {
    @Autowired
    private UserService userService;
    //注册
    @ApiOperation("注册接口")
    @PostMapping("/register")
    public void register(@RequestBody RegisterDto registerDto){
        userService.register(registerDto);
    }
    //登录
    @ApiOperation("登录接口")
    @PostMapping("/login")
    public R<UserEntity> login(HttpServletRequest request, @RequestBody UserDto userDto){
        return userService.login(request,userDto);

    }
    //    退出
    @ApiOperation("退出接口")
    @PostMapping("/logout")
    public R<String> logout(HttpServletRequest request){
        //清理session中保存的数据
        request.getSession().removeAttribute("user");
        return R.success("退出成功");

    }

    @ApiOperation("查找全部陪护师")
    @GetMapping("/nurseList")
    public R getNurseList(){
        UserEntity user=new UserEntity();
        user.setRole(1);
        return R.success(userService.getNurseList(user));
    }
}
